<template>
  <el-row type="flex" align="middle" justify="center" class="error-page">
    <div class="title">404</div>
    <div class="desc">Oh~~您的页面好像飞走了~</div>
    <el-row>
      <el-button type="primary" round size="small" @click="backHome">返回首页</el-button>
      <el-button type="primary" round size="small" @click="backPrev"
        >返回上一页({{ second }}s)</el-button
      >
    </el-row>
  </el-row>
</template>

<script>
export default {
  data() {
    return {
      second: 5,
      timer: null
    }
  },
  mounted() {
    // 5s返回上一页
    this.timer = setInterval(() => {
      if (this.second === 0) this.backPrev()
      else this.second--
    }, 1000)
  },
  methods: {
    // 返回上一页
    backPrev() {
      this.$router.go(-1)
    },
    // 返回首页
    backHome() {
      this.$router.push({ name: 'homepage' })
    }
  },
  beforeDestroy() {
    clearInterval(this.timer)
  }
}
</script>

<style lang="scss" scoped>
.error-page {
  width: 100vw;
  height: 100vh;
  flex-direction: column;
  .title {
    font-size: 80px;
    font-weight: bold;
    @include edu-color-primary;
  }
  .desc {
    font-size: 18px;
    font-weight: bold;
    color: $text-color-secondary;
    margin: 20px 0 50px;
  }
}
</style>
